package com.jxs.android.weiget;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.jxs.android.cmcc.data.MenuInfo;

public class MenuPageView extends GridView {
	private Context context;

	private ArrayList<MenuInfo> menuInfos = new ArrayList<MenuInfo>();
	private ItemClickListern itemClickListern;

	public MenuPageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
	}

	public ArrayList<MenuInfo> getMenuInfos() {
		return menuInfos;
	}

	public void setMenuInfos(ArrayList<MenuInfo> mMenuInfos) {
		this.menuInfos = mMenuInfos;
		MenuPageAdapter pageAdapter = new MenuPageAdapter(context, mMenuInfos);
		this.setAdapter(pageAdapter);
		this.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parentView, View view, int position, long arg3) {
				if (null != itemClickListern) {
					itemClickListern.callBack(menuInfos.get(position));
				}
			}

		});
	}

	public void setItemClickListern(ItemClickListern itemClickListern) {
		this.itemClickListern = itemClickListern;
	}

	static public interface ItemClickListern {
		public void callBack(MenuInfo menuInfo);
	}

}
